﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_PatnMasterIdx : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "MainPatnMasterIdx",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MasterIdxType = table.Column<int>(type: "integer", nullable: false),
                    MaterIdxValue = table.Column<string>(type: "text", nullable: false),
                    PatnId = table.Column<string>(type: "text", nullable: false),
                    PatnName = table.Column<string>(type: "text", nullable: false),
                    Gend = table.Column<int>(type: "integer", nullable: false),
                    Brdy = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainPatnMasterIdx", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainPatnBaseInfo",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PatnMasterIdxId = table.Column<Guid>(type: "uuid", nullable: false),
                    PatnId = table.Column<string>(type: "text", nullable: false),
                    PstnName = table.Column<string>(type: "text", nullable: false),
                    Gend = table.Column<int>(type: "integer", nullable: true),
                    Brdy = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    Age = table.Column<int>(type: "integer", nullable: true),
                    AgeUnt = table.Column<int>(type: "integer", nullable: true),
                    MrgStasCode = table.Column<string>(type: "text", nullable: true),
                    MrgStasName = table.Column<string>(type: "text", nullable: true),
                    NtlyCode = table.Column<string>(type: "text", nullable: true),
                    NtlyName = table.Column<string>(type: "text", nullable: true),
                    NatyCode = table.Column<string>(type: "text", nullable: true),
                    NatyName = table.Column<string>(type: "text", nullable: true),
                    Napl = table.Column<string>(type: "text", nullable: true),
                    PrfsCode = table.Column<string>(type: "text", nullable: true),
                    PrfsName = table.Column<string>(type: "text", nullable: true),
                    Tel = table.Column<string>(type: "text", nullable: true),
                    Addr = table.Column<string>(type: "text", nullable: true),
                    PsnCertTypeCode = table.Column<string>(type: "text", nullable: true),
                    PsnCertTypeName = table.Column<string>(type: "text", nullable: true),
                    Certno = table.Column<string>(type: "text", nullable: true),
                    PatnHgt = table.Column<float>(type: "real", nullable: true),
                    PatnWt = table.Column<float>(type: "real", nullable: true),
                    NwbFlag = table.Column<bool>(type: "boolean", nullable: false),
                    NwbAge = table.Column<string>(type: "text", nullable: true),
                    NwbBirWt = table.Column<float>(type: "real", nullable: true),
                    Birplc = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainPatnBaseInfo", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainPatnBaseInfo_MainPatnMasterIdx_PatnMasterIdxId",
                        column: x => x.PatnMasterIdxId,
                        principalTable: "MainPatnMasterIdx",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainPatnCardInfo",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PatnMasterIdxId = table.Column<Guid>(type: "uuid", nullable: false),
                    CardTypeCode = table.Column<string>(type: "text", nullable: false),
                    CardTypeName = table.Column<string>(type: "text", nullable: false),
                    CardId = table.Column<string>(type: "text", nullable: false),
                    CardNo = table.Column<string>(type: "text", nullable: false),
                    Stas = table.Column<int>(type: "integer", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainPatnCardInfo", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainPatnCardInfo_MainPatnMasterIdx_PatnMasterIdxId",
                        column: x => x.PatnMasterIdxId,
                        principalTable: "MainPatnMasterIdx",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainPatnBaseInfo_PatnMasterIdxId",
                table: "MainPatnBaseInfo",
                column: "PatnMasterIdxId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_MainPatnCardInfo_PatnMasterIdxId",
                table: "MainPatnCardInfo",
                column: "PatnMasterIdxId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainPatnBaseInfo");

            migrationBuilder.DropTable(
                name: "MainPatnCardInfo");

            migrationBuilder.DropTable(
                name: "MainPatnMasterIdx");
        }
    }
}
